<?php

namespace app\model;



/**
 * @property integer $id 主键(主键)
 * @property integer $user_id 用户编号
 * @property integer $factory_id 工厂编号
 * @property integer $lv 当前等级
 * @property integer $build_time 预计建造完成时间(秒)
 * @property integer $seat_num 当前空置槽位数
 * @property integer $max_seat_num 最大槽位数
 * @property string $material_ids 解锁工具
 * @property integer $state 是否装备 0已购买  1建造中 2完成
 * @property string $position 位置
 * @property string $build_end_time 预计建造完成时间
 * @property string $created_at 创建时间
 * @property string $updated_at 更新时间
 * @property string $deleted_at 删除时间
 */
class UserFactory extends Base
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'wa_user_factory';

    /**
     * The primary key associated with the table.
     *
     * @var string
     */
    protected $primaryKey = 'id';





    public function needTime(): \think\model\relation\HasOne
    {
        return $this->hasOne(Factory::class,'id','factory_id')->bind(['need_time_second' => 'need_time']);

    }

    public function factory(): \think\model\relation\HasOne
    {
        return $this->hasOne(Factory::class,'id','factory_id');

    }

    public function factoryMaxNum(): \think\model\relation\HasOne
    {
        return $this->hasOne(Factory::class,'id','factory_id')->bind(['max_num']);

    }

    //工具
    public function material(): \think\model\relation\HasMany
    {
        return $this->hasMany(Material::class,'factory_id','factory_id');
    }

    //槽位
    public function seat(): \think\model\relation\HasMany
    {
        return $this->hasMany(UserFactorySeat::class,'user_factory_id','id');
    }


    //生成队列
    public function queue(): \think\model\relation\HasMany
    {
        return $this->hasMany(UserFactorySeat::class,'user_factory_id','id')->where('status','<>',3);
    }

}
